if [ "$TERM_PROGRAM" != "Apple_Terminal" ]; then
  eval "$(oh-my-posh init zsh --config $HOME/.config/oh-my-posh/catppuccin_macchiato.omp.json)"
fi

source ~/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source ~/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source ~/.bash_aliases
source ~/.aliases
source ~/.environment

source <(fzf --zsh)

fzf-file-widget-smart-root() {
    setopt localoptions pipefail no_aliases 2>/dev/null

    local -a words
    local last raw root sel
    words=(${(z)LBUFFER})
    last=${words[-1]}
    raw=${(Q)last}             # unquote shell word
    root=${~raw}               # expand ~

    if [[ -n "$raw" && "$raw" == */ && -d "$root" ]]; then
      sel="$(cd -- "$root" && __fzf_select)" || return
      LBUFFER+="$sel"
    else
      LBUFFER+="$(__fzf_select)"
    fi

    zle reset-prompt
}

zle -N fzf-file-widget-smart-root
bindkey -M emacs '^T' fzf-file-widget-smart-root
bindkey -M vicmd '^T' fzf-file-widget-smart-root
bindkey -M viins '^T' fzf-file-widget-smart-root

eval $(thefuck --alias)

HISTFILE=~/.zsh_history
HISTCONTROL=ignoreboth
HISTSIZE=10000       # max lines kept in memory
SAVEHIST=10000       # max lines saved to $HISTFILE

# 2. Behavior flags
setopt APPEND_HISTORY     # append, don’t rewrite the entire file on exit
setopt INC_APPEND_HISTORY # write each command as it’s entered
setopt SHARE_HISTORY      # merge history across all running zsh’s
setopt HIST_IGNORE_ALL_DUPS  # don’t record a command if it’s already in history
setopt HIST_IGNORE_SPACE     # don’t record commands that start with a space

# fpath=(/Users/sudacode/.docker/completions $fpath)
FPATH="$HOME/.docker/completions:$FPATH"

[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"
eval "$(fnm env --use-on-cd --shell zsh)"

bindkey -v
# zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
# zstyle ':completion:*' menu select

# Substring search
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
# mac
# source $HOMEBREW_PREFIX/share/zsh-history-substring-search/zsh-history-substring-search.zsh

# Bind arrow keys for vi insert mode
bindkey -M viins '^[[A' history-substring-search-up
bindkey -M viins '^[[B' history-substring-search-down
# Also bind arrow keys for vi command mode
bindkey -M vicmd '^[[A' history-substring-search-up
bindkey -M vicmd '^[[B' history-substring-search-down
bindkey '^ ' autosuggest-accept

# The following lines were added by compinstall

zstyle ':completion:*' completer _complete _ignored _match _approximate
zstyle ':completion:*' completions 1
zstyle ':completion:*' insert-unambiguous false
zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*' max-errors 2
zstyle ':completion:*' menu select=long
zstyle ':completion:*' original true
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' substitute 1
# zstyle :compinstall filename '/Users/sudacode/.zshrc'
zstyle :compinstall filename /home/sudacode/.zsh/.zshrc

autoload -Uz compinit
compinit

# load both the URL‐quoting and paste‐magic widgets
autoload -Uz url-quote-magic bracketed-paste-magic

# tell url-quote-magic which chars to escape
zstyle ':url-quote-magic:*' url-quotes ''

# bind it to both typing and pasting
zle   -N self-insert       url-quote-magic
zle   -N bracketed-paste   bracketed-paste-magic

alias claude-mem='bun "/home/sudacode/.claude/plugins/marketplaces/thedotmack/plugin/scripts/worker-service.cjs"'
fpath=(/home/sudacode/.zsh/completions $fpath)
autoload -Uz compinit && compinit

# pnpm
export PNPM_HOME="/home/sudacode/.local/share/pnpm"
case ":$PATH:" in
  *":$PNPM_HOME:"*) ;;
  *) export PATH="$PNPM_HOME:$PATH" ;;
esac
# pnpm end
